<template>
    <!--活动的详细信息-->
    <div>
        <el-descriptions title="推广详情" :column="1" border>
            <el-descriptions-item label="分发标题">{{ this.rowData.title}}</el-descriptions-item>
            <el-descriptions-item label="活动ID">{{ this.rowData.taskId}}</el-descriptions-item>
            <el-descriptions-item label="活动状态">
              <span v-if="this.rowData.taskStatus =='0'"> 启用中..</span>
              <span v-else>停用..</span>
            </el-descriptions-item>
<!--            <el-descriptions-item label="视频标题">{{ this.rowData.title}}</el-descriptions-item>
            <el-descriptions-item label="视频话题">{{ this.rowData.videoTopic}}</el-descriptions-item>-->
            <el-descriptions-item label="活动地址">{{ this.rowData.taskAddress}}</el-descriptions-item>
            <el-descriptions-item label="活动二维码">
                <div class="block">
                    <span v-if="qrCodeSrc==undefined" class="demonstration">加载失败</span>
                    <img :src="qrCodeSrc" alt="">
                </div>
            </el-descriptions-item>
            <el-descriptions-item label="创建人">{{ this.rowData.taskCreateUserName}}</el-descriptions-item>
            <el-descriptions-item label="创建时间">{{ this.rowData.taskCreateTime}}</el-descriptions-item>


          <el-descriptions-item label="视频标题">
            <el-input v-model="rowData.title" type="textarea"
                      :autosize="{minRows: 4, maxRows: 4}"
                      :style="{width: '100%'}"
                      placeholder="更改视频标题">
            </el-input>
          </el-descriptions-item>
          <el-descriptions-item label="视频话题">
            <el-input v-model="rowData.videoTopic"
                      placeholder="更改视频话题"
                      type="textarea"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}">
            </el-input>
          </el-descriptions-item>
        </el-descriptions>
        <el-row type="flex" class="updateBtn" style="width: 100%" justify="end">
          <el-col :span="4">
            <el-button @click="updateFrom">更新</el-button>
            <el-button  @click="confirmOk" type="primary" >确定</el-button>
          </el-col>
        </el-row>
    </div>
</template>
<script>
import QRCode from 'qrcode'
import {updateTasks} from "@/api/tuike/qrCode";
export default {
    name: "qrCodeDetails",
    props:['rowData'],
    data() {
        return {
            qrCodeSrc: undefined,
            fromData:{
              videoTitle:"",
              videoTopic: "",
              taskId:"",
            }
        };
    },
    created() {
        console.log(this.rowData)
        if(this.rowData !=undefined){
            QRCode.toDataURL(this.rowData.taskAddress, { errorCorrectionLevel: 'H' })
            .then(url => {
                this.qrCodeSrc = url
            })
            .catch(err => {
                console.error(err)
            })
        }
    },
    methods: {
      updateFrom(){
         console.log(this.rowData);
         this.fromData.takskId = this.rowData.takskId;
         if(this.validate()){
            updateTasks(this.rowData).then(response =>{
              if (response.code === 200) {
                this.$message.success("更新成功")
              } else {
                this.$message.error("更新失败")
              }
            }

            )
         }else {
           this.$message({message:"请检查更改内容",type:"error"});
         }
      },
      confirmOk(){
        console.log(this.$parent);
        //this.$parent.visible = false;
        this.$emit('update:visible', false);
      },
      validate(){
        let valid = true;
        if(this.rowData.title ==""){
          valid = false
        }
        const topics = this.rowData.videoTopic.split('/#(.+?)/g');
        if(topics.length ==0){
          valid = false
        }
        return valid;
      }
    }
 };
 </script>
<style lang="scss">
.updateBtn{
  margin-top: 20px;
}
.qrDetailsUpdate{
  margin-top: 20px;
  label{
    box-sizing: border-box;
    text-align: left;
    font-weight: normal;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-all;
  }
  .el-form-item{
     border-spacing: 2px;
     border: 1px solid #e6ebf5;
    .el-form-item__label{
      color: #909399;
      background: #fafafa;
    }
  }

  .item{
    padding: 4px;

  }
}
</style>
